package com.robusta.cityuate.activities;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import com.robusta.cityuate.R;
import com.robusta.cityuate.base.CityuateFragmentMenuActivity;
import com.robusta.cityuate.fragments.SpotsListFragment;

public class ManageMyspotsActivity extends CityuateFragmentMenuActivity {
	
	private Context mContext = this;
	private ActionBar mActionBar;

	public static final String DEL_TAG = ManageMyspotsActivity.class.getName()
			+ "_DELSPOT";
	
	private SpotsListFragment spotsFragment;

	@Override
	public void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		setContentView(R.layout.manage_my_spots_view);
		
		mActionBar = getSupportActionBar();
		mActionBar.setTitle(R.string.spot_list);
		spotsFragment = SpotsListFragment.getInstant(mContext, 1);
		 FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
         ft.add(R.id.frag_holder, spotsFragment).commit();	
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle item selection
		switch (item.getItemId()) {
		case R.id.new_spot:
			Intent newSpot = new Intent(this, SpotCreateEditActivity.class);
			this.startActivityForResult(newSpot,
					SpotCreateEditActivity.SPOT_CREATEEDIT_CODE);
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getSupportMenuInflater();
		inflater.inflate(R.menu.spots_option_menu, menu);
//		menu.findItem(R.id.delete_multi).setEnabled(false);
		return super.onCreateOptionsMenu(menu);
	}
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode,
			Intent intent) {
		super.onActivityResult(requestCode, resultCode, intent);
		if (requestCode == SpotCreateEditActivity.SPOT_CREATEEDIT_CODE)
			if (resultCode == RESULT_OK)
				spotsFragment.reloadList();

	}

}
